package cn.tedu.boot012.controller;

import cn.tedu.boot012.entity.User;
import cn.tedu.boot012.until.DBUntil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@Controller
public class regController {
    @RequestMapping("/reg")
    @ResponseBody
    public String reg(User user) {

        try (Connection con = DBUntil.getConnection();) {
            String sql = "insert into user values(null,?,?,?)";
            PreparedStatement pst = con.prepareStatement(sql);
            pst.setString(1,user.getUsername());
            pst.setString(2,user.getPassword());
            pst.setString(3,user.getNickname());
            pst.executeUpdate();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        System.out.println("user = " + user);
        return "注册成功";

    }

}
